 <template>
  <!-- 封装echarts -->
  <div>
    <div ref="ebox" class="ebox">
      <!-- 装图表的盒子 -->

    </div>
  </div>

</template>

<script>
//引入echarts
import * as echarts from "echarts";
export default {
  //子接收父传过来的数据
  props: {
    msg: {
      type: Object,
      default: () => ({}),
    },
  },

  //在mounted生命周期中使用echarts,因为echarts需要使用dom节点
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(this.$refs.ebox);
    // 绘制图表
    let option = {
      title: {
        text: this.msg.title,
      },
      tooltip: {
        trigger: "axis",
      },
      legend: {
        data: this.msg.legend,
      },
      grid: {
        left: "8%",
        right: "8%",
        bottom: "8%",
        top: "15%",
        containLabel: true,
      },

      xAxis: {
        type: "category",
        boundaryGap: false,
        data: this.msg.xData,
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          name: this.msg.legend[0],
          type: "line",
          data: this.msg.amountData,
        },
        {
          name: this.msg.legend[1],
          type: "line",
          data: this.msg.orderData,
        },
      ],
    };
    myChart.setOption(option);
  },
};
</script>

<style lang="less" scoped>
.ebox {
  width: 100%;
  height: 350px;
  background-color: #fff;
  padding: 10px;
  margin-top: 20px;
}
</style>